<template>
  <div class="facility">
    <el-select v-model="selected">
      <el-option
        v-for="item in options"
        :key="item.value"
        :label="item.label"
        :value="item.value"
      />
    </el-select>
    <div class="list">
      <div class="item" ref="chartContainer">
        <img src="@/assets/index/meter.png" alt="" />
        <div class="text">入口流量</div>
      </div>
      <div class="item" ref="chartContainer2">
        <img src="@/assets/index/meter.png" alt="" />
        <div class="text">出口流量</div>
      </div>
    </div>
  </div>
</template>
<script setup>
import { ref, onMounted, onUnmounted } from "vue";
import * as echarts from "echarts";
const selected = ref("1");
const options = [
  {
    value: "1",
    label: "设备1",
  },
  {
    value: "2",
    label: "设备2",
  },
];
const chartContainer = ref();
let chart = null;

const initChart = () => {
  if (chartContainer.value) {
    chart = echarts.init(chartContainer.value);
    const option = {
      tooltip: {
        formatter: "{a} <br/>{b} : {c}%",
      },
      series: [
        {
          name: "Pressure",
          type: "gauge",
          progress: {
            show: true,
          },
          detail: {
            valueAnimation: true,
            formatter: "{value}",
          },
          data: [
            {
              value: 50,
              name: "SCORE",
            },
          ],
        },
      ],
    };
    chart.setOption(option);
  }
};

// const handleResize = () => {
//   chart?.resize();
// };

// onMounted(() => {
//   initChart();
//   window.addEventListener("resize", handleResize);
// });

// onUnmounted(() => {
//   chart?.dispose();
//   window.removeEventListener("resize", handleResize);
// });
</script>
<style lang="scss" scoped>
.el-select {
  width: 131px;
  height: 32px;
  background: #0f5a75;
  border-radius: 2px 2px 2px 2px;
  border: 1px solid #104b66;
  opacity: 0.5;
  margin: 6px 8px;
}
.list {
  display: flex;
  .item {
    flex: 1;
    height: 130px;
    text-align: center;
    position: relative;
    img {
      width: 100%;
      height: 100%;
      object-fit: contain;
    }
    .text {
      position: absolute;
      left: 50%;
      bottom: 2%;
      transform: translateX(-50%);
      font-weight: 400;
      font-size: 12px;
      color: #adc0e6;
      line-height: 16px;
    }
  }
}
</style>